home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / mac / After Effects 3.1 SDK Mac / Examples / UI Samples / Custom UI in fx window / AEFX_FXwin.c next >
Encoding:
C/C++ Source or Header  |  1996-11-06  |  8.0 KB  |  382 lines  |  [TEXT/CWIE]

  1. /**
  2.     AEFX_FXwin.c
  3.     
  4.     Part of the Adobe After Effects 3.1 SDK    
  5.     Copyright (c)1993-96, Adobe Systems Inc, All Rights Reserved.
  6.     
  7.     FX window UI sample
  8.  
  9.     Revision History
  10.         1.0, created by dmw
  11. **/
  12.  
  13. #include "AE_Effect.h"
  14. #include "AE_EffectCB.h"
  15. #include "AE_EffectUI.h"
  16. #include "AE_Macros.h"
  17.  
  18. #include <math.h>
  19. #include "AEFX_FXwin.h"
  20. #include "AEFX_UILib.h"
  21.  
  22. #define    MAJOR_VERSION        1L
  23. #define    MINOR_VERSION        1L
  24. #define    BUG_VERSION            0
  25. #define    STAGE_VERSION        PF_Stage_RELEASE
  26. #define    BUILD_VERSION        0
  27. #define NAME                "FX Window UI"
  28. #define DESCRIPTION            "⌐1996 Adobe Systems, Inc."
  29. #define ID                    4055
  30.  
  31.  
  32. /** these are constants which identify the index of each parameter
  33.  ** in the param block
  34.  **/
  35.  
  36. static PF_Err About (
  37.     PF_InData        *in_data,
  38.     PF_OutData        *out_data,
  39.     PF_ParamDef        *params[],
  40.     PF_LayerDef        *output )
  41. {
  42.     PF_SPRINTF(out_data->return_msg,
  43.         "FX UI sample, v%ld.%ld (c) 1996 Adobe Systems, Inc.",
  44.         MAJOR_VERSION, MINOR_VERSION);
  45.  
  46.     return PF_Err_NONE;
  47. }
  48.  
  49.  
  50. static PF_Err GlobalSetup (
  51.     PF_InData        *in_data,
  52.     PF_OutData        *out_data,
  53.     PF_ParamDef        *params[],
  54.     PF_LayerDef        *output )
  55. {
  56.     PF_Err    err = PF_Err_NONE;
  57.  
  58.     out_data->my_version = PF_VERSION(MAJOR_VERSION, MINOR_VERSION,
  59.                                       BUG_VERSION, STAGE_VERSION, BUILD_VERSION);
  60.  
  61.     out_data->out_flags = PF_OutFlag_CUSTOM_UI | PF_OutFlag_PIX_INDEPENDENT | PF_OutFlag_SEQUENCE_DATA_NEEDS_FLATTENING;
  62.  
  63.     return err;
  64. }
  65.  
  66.  
  67. static PF_Err GlobalSetdown (
  68.     PF_InData        *in_data,
  69.     PF_OutData        *out_data,
  70.     PF_ParamDef        *params[],
  71.     PF_LayerDef        *output )
  72. {
  73.     PF_Err             err = PF_Err_NONE;
  74.  
  75.     return err;    
  76. }
  77.  
  78.  
  79. #define UI_BOX_WIDTH            262
  80. #define UI_BOX_HEIGHT            102
  81.  
  82. static PF_Err ParamsSetup (
  83.     PF_InData        *in_data,
  84.     PF_OutData        *out_data,
  85.     PF_ParamDef        *params[],
  86.     PF_LayerDef        *output )
  87. {
  88.     PF_Err             err = PF_Err_NONE;
  89.     PF_ParamDef        def;
  90.  
  91.     AEFX_CLR_STRUCT(def)
  92.  
  93.     def.changed = 0;
  94.     def.ui_flags = PF_PUI_CONTROL;
  95.     def.ui_width = UI_BOX_WIDTH;
  96.     def.ui_height = UI_BOX_HEIGHT;
  97.     def.param_type = PF_Param_FIX_SLIDER;
  98.     PF_ADD_NULL("Histogram"); 
  99.     
  100.     AEFX_CLR_STRUCT(def)
  101.     PF_ADD_POPUP("Channel",  EX_Channel_CHANS_PLUS - 1, EX_Channel_LUM, "Luminance|Red|Green|Blue|Alpha");
  102.     PF_ADD_SLIDER("Black Point", 0, 255, 0, 255, 0);
  103.     PF_ADD_SLIDER("White Point",  0, 255, 0, 255, 255);
  104.     PF_ADD_SLIDER("Black Softness",  0, 255, 0, 255, 0);
  105.     PF_ADD_SLIDER("White Softness",  0, 255, 0, 255, 0);
  106.  
  107.     def.flags = 0;
  108.     def.param_type = PF_Param_CHECKBOX;
  109.     def.u.bd.value = def.u.bd.dephault = FALSE;
  110.     def.u.bd.u.nameptr = "";
  111.     PF_STRCPY(def.name, "Invert" );
  112.     if (err = PF_ADD_PARAM(in_data, -1, &def)) return err;
  113.  
  114.     out_data->num_params = EX_NUM_PARAMS;
  115.         
  116.     if (!err) {
  117.         PF_CustomUIInfo        ci;
  118.         
  119.         ci.events = PF_CustomEFlag_EFFECT;
  120.          
  121.         ci.comp_ui_width = ci.comp_ui_height = 0;
  122.         ci.comp_ui_alignment = PF_UIAlignment_NONE;
  123.         
  124.         ci.layer_ui_width = ci.layer_ui_height = 0;
  125.         ci.layer_ui_alignment = PF_UIAlignment_NONE;
  126.         
  127.         ci.preview_ui_width = ci.preview_ui_height = 0;
  128.         ci.preview_ui_alignment = PF_UIAlignment_NONE;
  129.  
  130.         err = (*(in_data->inter.register_ui))(in_data->effect_ref, &ci);
  131.     }
  132.     
  133.     return err;
  134. }
  135.  
  136.  
  137. static PF_Err SequenceSetup (
  138.     PF_InData        *in_data,
  139.     PF_OutData        *out_data,
  140.     PF_ParamDef        *params[],
  141.     PF_LayerDef        *output )
  142. {
  143.     PF_Err            err = PF_Err_NONE;
  144.     EX_Globals        **globs;
  145.     EX_Globals        *globals;
  146.  
  147.     if (in_data->sequence_data) {
  148.         DisposeHandle(in_data->sequence_data);
  149.         out_data->sequence_data = NULL;
  150.     }
  151.     
  152.     globs = (EX_Globals**)NewHandle(sizeof(EX_Globals));
  153.  
  154.     if (globs) {
  155.         in_data->sequence_data = out_data->sequence_data = (Handle)globs;
  156.         HLock((Handle)globs);
  157.         globals = *globs;
  158.         globals->freshHist = FALSE;
  159.         
  160.         SetRect(&globals->offRect,0,0,EX_HIST_WIDTH,EX_HIST_HEIGHT);
  161.         if (!CreateOffscreenBitMap(&globals->graphbits, 1, &globals->offRect)) {
  162.             err = memFullErr;
  163.         }
  164.         
  165.         SetRect(&globals->wedgeRect,0,0,EX_HIST_WIDTH,EX_WEDGE_HEIGHT);
  166.         if (!CreateOffscreenBitMap(&globals->wedgebits, 1, &globals->wedgeRect)) {
  167.             err = memFullErr;
  168.         }
  169.         
  170.         if (!err)         globals->magic = EX_MAGIC;
  171.  
  172.         HUnlock((Handle)globs);
  173.         
  174.     } else {
  175.         err = memFullErr;
  176.     }
  177.     
  178.     if (err) {
  179.         PF_SPRINTF(out_data->return_msg, "Not enough memory to execute"NAME);
  180.         out_data->out_flags |= PF_OutFlag_DISPLAY_ERROR_MESSAGE;
  181.     }
  182.     
  183.     return err;
  184.  
  185. }
  186.  
  187.  
  188. PF_Err SequenceResetup (
  189.     PF_InData        *in_data,
  190.     PF_OutData        *out_data,
  191.     PF_ParamDef        *params[],
  192.     PF_LayerDef        *output )
  193. {
  194.     return (SequenceSetup(in_data, out_data, params, output));
  195. }
  196.  
  197.  
  198. static PF_Err SequenceSetdown (
  199.     PF_InData        *in_data,
  200.     PF_OutData        *out_data,
  201.     PF_ParamDef        *params[],
  202.     PF_LayerDef        *output )
  203. {
  204.     PF_Err            err = PF_Err_NONE;
  205.     EX_Globals        **globals;
  206.     
  207.     if (in_data->sequence_data) {
  208.         globals = (EX_Globals**)in_data->sequence_data;
  209.         DestroyOffscreenBitMap(DH(globals)->graphbits);
  210.         DestroyOffscreenBitMap(DH(globals)->wedgebits);
  211.         DH(globals)->graphbits = DH(globals)->wedgebits = NULL;
  212.         DisposeHandle(in_data->sequence_data);
  213.         out_data->sequence_data = NULL;
  214.     }
  215.     return err;
  216.  
  217. }
  218.  
  219.  
  220. static PF_Err SequenceFlatten (
  221.     PF_InData        *in_data,
  222.     PF_OutData        *out_data,
  223.     PF_ParamDef        *params[],
  224.     PF_LayerDef        *output )
  225. {
  226.     PF_Err        err = PF_Err_NONE;
  227.  
  228.     err = SequenceSetdown(in_data, out_data, params, output);
  229.         
  230.     return err;
  231. }
  232.  
  233.  
  234. /** FrameSetup (does the buffer resize)
  235.  **/
  236.  
  237. static PF_Err FrameSetup (
  238.     PF_InData        *in_data,
  239.     PF_OutData        *out_data,
  240.     PF_ParamDef        *params[],
  241.     PF_LayerDef        *output )
  242. {
  243.     PF_Err            err = PF_Err_NONE;
  244.     return err;
  245.  
  246. }
  247.     
  248. #define LOOP_PIXELS_START                        \
  249.     for (y=0; y<output->height; y++) {            \
  250.         for (x=0; x<output->width; x++) {        
  251.  
  252.  
  253. #define LOOP_PIXELS_END                            \
  254.             ++src; ++dst;                        \
  255.         }                                        \
  256.         src += s_skip;                            \
  257.         dst += d_skip;                            \
  258.         if ((y%32) == 0) {                        \
  259.             err = PF_PROGRESS(in_data, y, output->height);        \
  260.             if (err) break;                        \
  261.         }                                        \
  262.                                                 \
  263.     }                                        
  264.  
  265.  
  266. static PF_Err Render (
  267.     PF_InData        *in_data,
  268.     PF_OutData        *out_data,
  269.     PF_ParamDef        *params[],
  270.     PF_LayerDef        *output )
  271. {
  272.     PF_Err                err = PF_Err_NONE;
  273.     register PF_Pixel    *src, *dst;
  274.     register long         x, y;
  275.     long                s_skip, d_skip;
  276.     long                *hist;
  277.     EX_Globals            **globals;
  278.     
  279.     PF_Err (*app)(PF_ProgPtr, long, ...) =
  280.         ((PF_UtilCallbacks *)in_data->utils)->app;
  281.     
  282.     if (in_data->sequence_data == NULL) {
  283.         err = SequenceSetup(in_data, out_data, params, output);
  284.     }
  285.     
  286.     if (!err) {
  287.  
  288.         globals = (EX_Globals**)in_data->sequence_data;
  289.         hist = DH(globals)->hist;
  290.         s_skip = params[EX_INPUT]->u.ld.rowbytes/4 - params[EX_INPUT]->u.ld.width;
  291.         d_skip = output->rowbytes/4 - output->width;
  292.         
  293.         src = params[EX_INPUT]->u.ld.data;
  294.         dst = output->data;
  295.         
  296.         for (y=0; y<256; y++) {
  297.             hist[y] = 0;
  298.         }
  299.                 
  300.         if (!err) {
  301.             LOOP_PIXELS_START
  302.                 *dst = *src;
  303.                 hist[src->red] ++;
  304.             LOOP_PIXELS_END
  305.         }
  306.     }
  307.     
  308.     if (!err)  {
  309.         DH(globals)->freshHist = TRUE;
  310.         out_data->out_flags |= PF_OutFlag_REFRESH_UI;
  311.  
  312.     }
  313.     else DH(globals)->freshHist = FALSE;
  314.     
  315.     return err;
  316. }
  317.  
  318.  
  319. PF_Err HandleEvent (
  320.     PF_InData        *in_data,
  321.     PF_OutData        *out_data,
  322.     PF_ParamDef        *params[],
  323.     PF_LayerDef        *output,
  324.     PF_EventExtra    *event_extra );
  325.  
  326.  
  327. main (
  328.     PF_Cmd            cmd,
  329.     PF_InData        *in_data,
  330.     PF_OutData        *out_data,
  331.     PF_ParamDef        *params[],
  332.     PF_LayerDef        *output,
  333.     void            *extra )
  334. {
  335.     PF_Err        err = PF_Err_NONE;
  336.     AEFX_DECLARE_A4
  337.     
  338.     AEFX_SET_A4
  339.     
  340.     switch (cmd) {
  341.     case PF_Cmd_ABOUT:
  342.         err = About(in_data,out_data,params,output);
  343.         break;
  344.     case PF_Cmd_GLOBAL_SETUP:
  345.         err = GlobalSetup(in_data,out_data,params,output);
  346.         break;
  347.     case PF_Cmd_GLOBAL_SETDOWN:
  348.         err = GlobalSetdown(in_data,out_data,params,output);
  349.         break;
  350.     case PF_Cmd_PARAMS_SETUP:
  351.         err = ParamsSetup(in_data,out_data,params,output);
  352.         break;
  353.     case PF_Cmd_SEQUENCE_SETUP:
  354.         err = SequenceSetup(in_data,out_data,params,output);
  355.         break;
  356.     case PF_Cmd_SEQUENCE_SETDOWN:
  357.         err = SequenceSetdown(in_data,out_data,params,output);
  358.         break;
  359.     case PF_Cmd_SEQUENCE_RESETUP:
  360.         err = SequenceResetup(in_data,out_data,params,output);
  361.         break;
  362.     case PF_Cmd_SEQUENCE_FLATTEN:
  363.         err = SequenceFlatten(in_data,out_data,params,output);
  364.         break;
  365.     case PF_Cmd_FRAME_SETUP:
  366.         err = FrameSetup(in_data,out_data,params,output);
  367.         break;
  368.     case PF_Cmd_RENDER:
  369.         err = Render(in_data,out_data,params,output);
  370.         break;
  371.     case PF_Cmd_EVENT:
  372.         err = HandleEvent(in_data,out_data,params,output,extra);
  373.         break;
  374.     default:
  375.         break;
  376.     }
  377.  
  378.     
  379.     AEFX_RESTORE_A4
  380.     return err;
  381. }
  382.